package com.jeeplus.modules.api.utils;
import com.tencentcloudapi.common.Credential;
import com.tencentcloudapi.common.exception.TencentCloudSDKException;
import com.tencentcloudapi.common.profile.ClientProfile;
import com.tencentcloudapi.common.profile.HttpProfile;
import com.tencentcloudapi.sms.v20210111.SmsClient;
import com.tencentcloudapi.sms.v20210111.models.SendSmsRequest;
import com.tencentcloudapi.sms.v20210111.models.SendSmsResponse;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class TenSms {

    private static final String secretId = "AKIDc5LNDqIYaNvEdy77A5mFXegiimjT0NWd";
    private static final String secretKey = "BLNBrPmwxmTYZTEoHblfP8lGbjbEckcH";
    private static final String sdkAppId = "1400603072";
    private static final String signName = "开心密逃";
    private static final String templateId = "1216339";

    public static void main(String[] args) {
        String[] phoneNumberSet = {"+8613223083685"};
        String[] templateParamSet = {"123456"};
        sendSms(phoneNumberSet, templateParamSet);
    }

    public static void sendSms(String[] mobiles, String[] codes) {
        try {
            Credential cred = new Credential(secretId, secretKey);
            HttpProfile httpProfile = new HttpProfile();
            httpProfile.setReqMethod("POST");
            httpProfile.setConnTimeout(60);
            httpProfile.setEndpoint("sms.tencentcloudapi.com");
            ClientProfile clientProfile = new ClientProfile();
            clientProfile.setSignMethod("HmacSHA256");
            clientProfile.setHttpProfile(httpProfile);
            SmsClient client = new SmsClient(cred, "ap-guangzhou", clientProfile);
            SendSmsRequest req = new SendSmsRequest();
            req.setSmsSdkAppId(sdkAppId);
            req.setSignName(signName);
            String senderid = "";
            req.setSenderId(senderid);
            String sessionContext = "";
            req.setSessionContext(sessionContext);
            String extendCode = "";
            req.setExtendCode(extendCode);
            req.setTemplateId(templateId);
            req.setPhoneNumberSet(mobiles);
            req.setTemplateParamSet(codes);
            SendSmsResponse res = client.SendSms(req);
            log.info("返回信息:{}", SendSmsResponse.toJsonString(res));
            log.info("RequestId:{}", res.getRequestId());
        } catch (TencentCloudSDKException e) {
            e.printStackTrace();
        }
    }
}